// 压缩

const fs = require('fs')

const http = require('http')

const zlib = require('zlib')

const gzip = zlib.createGzip()

http.createServer((req,res) => {
  // res 就是可写流所以不用创建
  const rs = fs.createReadStream('./test.txt')
  // 告诉浏览器我是基于gzip压缩的
  res.writeHead(200,{"Content-Type":" text/plain; charset=UTF-8","Content-Encoding":"gzip"})
  
  rs.pipe(gzip).pipe(res)
}).listen(3000,() => {
  console.log('3000端口runing')
})